<template>
    <div>
        <el-container>
            <el-aside style=" width: 200px;">
                <Menu></Menu>
            </el-aside>

                  <el-container>
                    <el-header>
                         <h1>接口文档导入 <span style="color: grey;font-size: xx-small">（请先手动检查调整解析结果，然后点击导入即可把接口导入到自己的项目中）</span></h1>

                    </el-header>
                        <el-input  v-model="ad_url" style="margin-left: 25%;width: 50%;box-shadow: 4px 4px 8px grey" placeholder="请粘贴接口文档url到此">
                            <el-button @click="jx" slot="append" icon="el-icon-search">解析</el-button>
                        </el-input>

                       <el-main>
                            <el-card shadow="hover" style="width: 48%;float: left" >
                                <el-form :model="form_data">
                                    <el-form-item label="接口名称" label-width="80px">
                                        <el-input v-model="form_data.label"></el-input>
                                    </el-form-item>
                                    <el-form-item label="接口描述" label-width="80px">
                                        <el-input v-model="form_data.des"></el-input>
                                    </el-form-item>
                                    <el-form-item label="host域名" label-width="80px">
                                        <el-input v-model="form_data.host"></el-input>
                                    </el-form-item>
                                    <el-form-item label="path路径" label-width="80px">
                                        <el-input v-model="form_data.path"></el-input>
                                    </el-form-item>
                                    <el-form-item label="请求方式" label-width="80px">
                                        <el-radio-group v-model="form_data.method">
                                            <el-radio label="post">post</el-radio>
                                            <el-radio label="get">get</el-radio>
                                            <el-radio label="delete">delete</el-radio>
                                            <el-radio label="put">put</el-radio>
                                        </el-radio-group>
                                    </el-form-item>

                                    <el-form-item label="Headers" label-width="80px">
                                                            <el-input v-model="form_data.headers"></el-input>
                                    </el-form-item>

                                    <el-form-item label="Params" label-width="80px">
                                                            <el-input v-model="form_data.params"></el-input>
                                    </el-form-item>

                                    <el-form-item label="payload_method" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_method"></el-input>
                                    </el-form-item>

                                    <el-form-item label="payload_fd" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_fd"></el-input>
                                    </el-form-item>

                                    <el-form-item label="payload_xwfu" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_xwfu"></el-input>
                                    </el-form-item>
                                    <el-form-item label="payload_raw_method" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_raw_method"></el-input>
                                    </el-form-item>
                                    <el-form-item label="payload_raw" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_raw"></el-input>
                                    </el-form-item>
                                    <el-form-item label="payload_GQL_q" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_GQL_q"></el-input>
                                    </el-form-item>
                                    <el-form-item label="payload_GQL_g" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_GQL_g"></el-input>
                                    </el-form-item>
                                    <el-form-item label="payload_binary" label-width="120px">
                                                            <el-input type="textarea" :rows="3" v-model="form_data.payload_binary"></el-input>
                                    </el-form-item>


                                </el-form>
                            </el-card>
                            <el-card shadow="hover" style="width: 50%;float: right">
                                <el-table :data="project_list_data" style="width: 100%">
                                    <el-table-column label-width="100">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="success" @click="import_api_ad(scope.row.id)" >导入到此项目</el-button>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="项目id" label-width="100">
                                        <template slot-scope="scope">
                                            <span>{{ scope.row.id }}</span>
                                        </template>
                                    </el-table-column>
                                     <el-table-column label="创建者" label-width="100">
                                         <template slot-scope="scope">
                                            <span>{{ scope.row.creater_name }}</span>
                                        </template>
                                    </el-table-column>
                                     <el-table-column label="项目名称" label-width="100">
                                         <template slot-scope="scope">
                                            <span>{{ scope.row.name }}</span>
                                        </template>
                                    </el-table-column>
                                </el-table>
                           </el-card>
                        </el-main>

                  </el-container>
        </el-container>

    </div>
</template>

<script>
    import Menu from '../components/Menu'
    import axios from 'axios'
    export default {
        name: "Env_list",
        data(){
          return{
              ad_url:"",
              form_data:{
              },
              project_list_data:[],

            }
        },
        methods:{
            jx(){
              axios.get('http://localhost:8000/jx_apiDoc/',{
                  params:{
                        ad_url:this.ad_url
                  }
              }).then(res=>{
                  this.form_data = res.data
              })
            },
            import_api_ad(pro_ject_id){
                axios.post('http://localhost:8000/import_api_ad/',this.form_data,{
                    params:{
                        pro_ject_id:pro_ject_id
                    }
                }).then(res=>{
                     this.$message({
                        message:"导入成功",
                        type:'success',
                    })
                })
            },
        },
        mounted(){
           axios.get('http://localhost:8000/get_DATE/').then(res=>{
                    this.project_list_data = res.data
                })
        },
        components:{
            Menu
        }
    }
</script>

<style scoped>

</style>